package com.utc.teamcenter.common.app.dialog.bean;

import java.util.List;

import javax.swing.JComponent;

import com.teamcenter.rac.util.combobox.iComboBox;

public class BeanICombobox extends BeanComponent {

	private iComboBox comboBox;

	@SuppressWarnings("unchecked")
	public BeanICombobox(String key, String name, String value, List items,
			boolean required) {
		super(key, name);

		this.comboBox = new iComboBox(items);
		this.comboBox.setSelectedItem(value);

		this.comboBox.setMandatory(required);
	}

	@Override
	public void clear() {

	}

	@Override
	public JComponent getComponent() {
		return this.comboBox;
	}

	public Object getSelectedItem() {
		Object value = this.comboBox.getSelectedItem();

		if (value == null) {
			return null;
		}
		return value;
	}

	@Override
	public String getText() {
		Object value = this.comboBox.getSelectedItem();

		if (value == null) {
			return null;
		}

		return value.toString();
	}

	@Override
	public boolean isRequired() {
		return this.comboBox.isMandatory();
	}

	@Override
	public void requestFocus() {
		this.comboBox.requestFocus();
	}

	@Override
	public void setEnabled(boolean bool) {
		this.comboBox.setEnabled(bool);

	}

	@Override
	public void setRequired(boolean required) {
		this.comboBox.setMandatory(required);
	}

	@Override
	public void setText(String text) {
		this.comboBox.addItem(text);
	}

	@Override
	public void setVisible(boolean bool) {
		this.comboBox.setVisible(bool);
	}
	
	public void removeAllItems(){
		this.comboBox.removeAllItems();
	}

}
